package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDTO;
import com.zzyl.entity.NursingLevel;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zzyl.base.ResponseResult.success;

@RestController
@Api(tags = "护理等级管理")
public class NursingLevelController {
    @Autowired
    private NursingLevelService nursingLevelService;

    /**
     * 查询所有护理等级
     *
     * @return
     */
    @GetMapping("/nursingLevel/listAll")
    @ApiOperation(value = "查询所有护理等级")
    public ResponseResult<List<NursingLevelVO>> findAll() {
        List<NursingLevelVO> vo = nursingLevelService.findAll();
        return success(vo);
    }

    /**
     * 新增护理等级
     *
     * @param nursingLevelDTO
     * @return
     */
    @PostMapping("/nursingLevel/insert")
    @ApiOperation(value = "新增护理等级")
    public ResponseResult insertNursingLevel(@RequestBody NursingLevelDTO nursingLevelDTO) {
        nursingLevelService.insertNursingLevel(nursingLevelDTO);
        return success();
    }

    /**
     * 分页查询护理等级
     *
     * @param pageNum
     * @param pageSize
     * @param status
     * @param name
     * @return
     */
    @GetMapping("/nursingLevel/listByPage")
    @ApiOperation(value = "分页查询护理等级")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "状态", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "护理等级名称", required = false, dataType = "String", paramType = "query"),
    })
    public ResponseResult<PageResponse<NursingLevelVO>> listByPage(Integer pageNum,
                                                                   Integer pageSize,
                                                                   Integer status,
                                                                   String name) {
        PageResponse<NursingLevelVO> page = nursingLevelService.listByPage(pageNum, pageSize, status, name);
        return success(page);
    }

    @GetMapping("/nursingLevel/{id}")
    @ApiOperation(value = "根据id查询护理等级")
    public ResponseResult<NursingLevelVO> selectById(@PathVariable Long id) {
        NursingLevelVO voList = nursingLevelService.selectById(id);
        return success(voList);
    }

    @PutMapping("/nursingLevel/update")
    @ApiOperation(value = "修改护理等级")
    public ResponseResult updateNursingLevel(@RequestBody NursingLevelDTO nursingLevelDTO){
        nursingLevelService.updateNursingLevel(nursingLevelDTO);
        return success();
    }
    @PutMapping("/nursingLevel/{id}/status/{status}")
    @ApiOperation(value = "启用禁用状态")
    public ResponseResult editStatus(@PathVariable Integer id,@PathVariable Integer status){
        nursingLevelService.editStatus(id,status);
        return success();
    }

    /**
     * 根据id删除护理项目
     * @param id
     * @return
     */
    @DeleteMapping("/nursingLevel/delete/{id}")
    @ApiOperation(value = "根据id删除某一项护理")
    public ResponseResult deleteById(@PathVariable Integer id){
        nursingLevelService.deleteById(id);
        return success();
    }
}
